/*
 *有关于管理员帐户中设置的内容
 */
package com.res0w.SMMS.admin;

import com.res0w.SMMS.ds.SettingAlterItems;
import com.res0w.SMMS.ds.SettingQuarterFinal;
import com.res0w.SMMS.ds.SettingRelay;
import com.res0w.SMMS.ds.SettingScheduleNormal;
import com.res0w.SMMS.ds.SettingScore;
import com.res0w.SMMS.ds.settingNormal;
import com.res0w.SMMS.factory.DataBaseOperate;
import com.res0w.SMMS.fuction.DBInit;
import java.util.ArrayList;

/**
 *
 * @author res0w
 * @since 2009-9-21
 * @version 0.2
 */
public class Setting {

    public ArrayList alterReadList = new ArrayList();
    public ArrayList relayReadList = new ArrayList();
    private DataBaseOperate db;
    public String hostName;
    public int hostYear;
    public String hostSeason;
    public int bYear;
    public int bMonth;
    public int bDay;
    public int eYear;
    public int eMonth;
    public int eDay;
    private ArrayList list;
    public String alterItemsName;
    public String alterItemsType;
    public int alterBestChoice;
    public int alterSex;
    public int alterQFinial;
    public int alterGroupNo;
    public String relayItemsName;
    public int relayTeamPeopleCount;
    public int relaySex;
    public int relayQFinal;
    public int relayGroupNo;
    public int maxScore;
    public int minScore;
    public int peopleCount;
    public int bScRecord;
    public int teamPeopleCount;
    public int allPeopleCount;
    public int limitPerPerson;

    public Setting() {
        db = new DataBaseOperate();
        list = new ArrayList();
        if (!list.isEmpty()) {
            list.clear();
        }
    }

    public void onlyExe() {
        db.dbUpdateBatch(list);
    }

    private void clearTable(String tableName) {
        DBInit dbi = new DBInit();
        dbi.clearTable(tableName);
    }

    public void SettingPropertyUpdate(boolean isExe) {

        clearTable("setting_alteritems");
        clearTable("setting_relay");
        this.scoreSettingWrite();
        this.normalSettingWrite();
        this.quarterFinalSettingWrite();
        if (isExe) {
            db.dbUpdateBatch(list);
        }

    }

    public void SettingPropertyRead() {
        alterSettingRead();
        relaySettingRead();
        scoreSettingRead();
        normalSettingRead();
        quarterFinalSettingRead();

        db.dbClosed();
    }

    public void alterSettingWrite() {
        SettingAlterItems sat = new SettingAlterItems();

        sat.itemsName = alterItemsName;
        sat.itemsType = alterItemsType;
        sat.bestChoice = alterBestChoice;
        sat.sex = alterSex;
        sat.qFinal = alterQFinial;
        sat.groupNo = alterGroupNo;

        for (int i = 0; i < sat.exeSqls().length; i++) {
            list.add(sat.exeSqls()[i]);
        }
    }

    public void relaySettingWrite() {
        SettingRelay sat = new SettingRelay();

        sat.itemsName = relayItemsName;
        sat.teamPeopleCount = relayTeamPeopleCount;
        sat.sex = relaySex;
        sat.qFinal = relayQFinal;
        sat.groupNo = relayGroupNo;

        for (int i = 0; i < sat.exeSqls().length; i++) {
            list.add(sat.exeSqls()[i]);
        }
    }

    private void scoreSettingWrite() {
        SettingScore sat = new SettingScore();

        sat.maxScore = maxScore;
        sat.minScore = minScore;
        sat.peopleCount = peopleCount;
        sat.bScRecord = bScRecord;

        for (int i = 0; i < sat.exeSqls().length; i++) {
            list.add(sat.exeSqls()[i]);
        }
    }

    private void quarterFinalSettingWrite() {
        SettingQuarterFinal sat = new SettingQuarterFinal();
        sat.teamPeopleCount = teamPeopleCount;
        sat.allPeopleCount = allPeopleCount;

        for (int i = 0; i < sat.exeSqls().length; i++) {
            list.add(sat.exeSqls()[i]);
        }
    }

    private void normalSettingWrite() {
        settingNormal sat = new settingNormal();

        sat.limitPerPerson = limitPerPerson;

        for (int i = 0; i < sat.exeSqls().length; i++) {
            list.add(sat.exeSqls()[i]);
        }

        SettingScheduleNormal ssn = new SettingScheduleNormal();

        ssn.hostName = hostName;
        ssn.hostYear = hostYear;
        ssn.hostSeason = hostSeason;
        ssn.bYear = bYear;
        ssn.bMonth = bMonth;
        ssn.bDay = bDay;
        ssn.eYear = eYear;
        ssn.eMonth = eMonth;
        ssn.eDay = eDay;

        for (int i = 0; i < ssn.exeSqls().length; i++) {
            list.add(ssn.exeSqls()[i]);
        }
    }
///////////////////////////////////////////////////////////////////////////////

    public void alterSettingRead() {
        SettingAlterItems sat = new SettingAlterItems();
        sat.readSqls();
        alterReadList = sat.alterItemsList;
    }

    public void relaySettingRead() {
        SettingRelay sat = new SettingRelay();
        sat.readSqls();
        relayReadList = sat.relayList;
    }

    private void scoreSettingRead() {
        SettingScore sat = new SettingScore();
        sat.readSqls();
        maxScore = sat.maxScore;
        minScore = sat.minScore;
        peopleCount = sat.peopleCount;
        bScRecord = sat.bScRecord;
    }

    private void quarterFinalSettingRead() {
        SettingQuarterFinal sat = new SettingQuarterFinal();
        sat.readSqls();
        teamPeopleCount = sat.teamPeopleCount;
        allPeopleCount = sat.allPeopleCount;
    }

    private void normalSettingRead() {
        settingNormal sat = new settingNormal();
        sat.readSqls();
        limitPerPerson = sat.limitPerPerson;
        SettingScheduleNormal ssn = new SettingScheduleNormal();
        ssn.readSqls();
        hostName = ssn.hostName;
        hostYear = ssn.hostYear;
        hostSeason = ssn.hostSeason;
        bYear = ssn.bYear;
        bMonth = ssn.bMonth;
        bDay = ssn.bDay;
        eYear = ssn.eYear;
        eMonth = ssn.eMonth;
        eDay = ssn.eDay;
    }
}
